//
//  TopicTableViewCell.m
//  MyListenMusicFun
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TopicTableViewCell.h"

@implementation TopicTableViewCell



-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView NightWithType:UIViewColorTypeNormal];
        
        self.headerImgView = [[UIImageView alloc] init];
//        _headerImgView.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:_headerImgView];
        _headerImgView.layer.cornerRadius = 25;
        _headerImgView.clipsToBounds = YES;
        
        self.nameLabel = [[UILabel alloc] init];
//        _nameLabel.backgroundColor = [UIColor yellowColor];
        [_nameLabel NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_nameLabel];
        _nameLabel.textColor = [UIColor grayColor];
        _nameLabel.font = [UIFont systemFontOfSize:15];
        
        self.timeLabel = [[UILabel alloc] init];
//        _timeLabel.backgroundColor = [UIColor orangeColor];
        [_timeLabel NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_timeLabel];
        _timeLabel.textColor = [UIColor grayColor];
        _timeLabel.font = [UIFont systemFontOfSize:15];
        
        self.messageLabel = [[UILabel alloc] init];
//        _messageLabel.backgroundColor = [UIColor purpleColor];
        [_messageLabel NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_messageLabel];
        _messageLabel.numberOfLines = 0;
        _messageLabel.font = [UIFont systemFontOfSize:15];
        
        self.typeImgView = [[UIImageView alloc] init];
//        _typeImgView.backgroundColor = [UIColor greenColor];
        [_typeImgView NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_typeImgView];
        _typeImgView.image = [UIImage imageNamed:@"type"];
        
        self.typeLabel = [[UILabel alloc] init];
//        _typeLabel.backgroundColor = [UIColor blueColor];
        [_typeLabel NightWithType:UIViewColorTypeNormal];
        [self.contentView addSubview:_typeLabel];
        _typeLabel.textColor = [UIColor grayColor];
        _typeLabel.font = [UIFont systemFontOfSize:15];
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat h = [[self class]heightWithText:_messageLabel.text width:self.contentView.frame.size.width - 10];

    _headerImgView.frame = CGRectMake(10, 10, 50, 50);
    _nameLabel.frame = CGRectMake(70, 15, 200, 20);
    _timeLabel.frame = CGRectMake(70, 35, 200, 20);
    _messageLabel.frame = CGRectMake(10, 65, self.contentView.frame.size.width - 20, h);
    _typeImgView.frame = CGRectMake(10, 70 + h, 20, 20);
    _typeLabel.frame = CGRectMake(40, 70 + h, 100, 20);
}

//高度自适应方法
+(CGFloat)heightWithText:(NSString *)text width:(CGFloat)width{
    NSDictionary *dic = @{NSFontAttributeName: [UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(width, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
